<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>减少全局变量的声明</title>
</head>
<body>
<script>
    let name = 'tom';
    let age = 25;
    function greet() {
        console.log(`hello,${name}!`);
    }
    function getBirthYear() {
        return new Date().getFullYear() - age;
    }
    //将用户信息封装到一个单独对象中
    let user = {
        name : 'tom',
        age : 25
    }
    function greet() {
        console.log(`hello,${user.name}!`);
    }
    function getBirthYear() {
        return new Date().getFullYear() - user.age;
    }
    //优化函数的参数
    function greet(user) {
        console.log(`hello,${user.name}!`);
    }
    function getBirthYear(user) {
        return new Date().getFullYear() - user.age;
    }
</script>


</body>
</html>